import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/27 8:59
 * 汽水瓶子
 *  查找两个字符串 a,b中的最长公共字串
 */
public class Day19 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();


        System.out.println(solution(str1, str2));
//        while (scanner.hasNext()){
//            int num = scanner.nextInt();
//            if (num==0){
//                break;
//            }
//            System.out.println(solution1(num));
//        }
    }
    //------------------------------------------------------- DP
    public static String solution(String str1 ,String str2){
        String tem ;
        if (str1.length() > str2.length()){
            tem = str1;
            str1 = str2;
            str2 = tem;
        }
        int start = 0;
        int end = 0;
        int max = 0;
        //初始化
        int[][] ints = new int[str1.length()+1][str2.length()+1];
        for (int i = 1; i < str2.length()+1; i++) {
            ints[0][i] = str2.charAt(i-1);
        }
        for (int i = 1; i < str1.length()+1; i++) {
            ints[i][0] = str1.charAt(i-1);
        }
        int[][] dp = new int[str1.length()+1][str2.length()+1];
        // 状态转移方程
        for (int i = 1; i < str1.length()+1; i++) {
            for (int j = 1; j < str2.length()+1; j++) {
                if (ints[i][0] == ints[0][j]){
                    dp[i][j] = dp[i-1][j-1] +1;
                }
                if (dp[i][j] > max ) {
                    max = dp[i][j];
                    start = i - max  ;
                    end = i;
                }
            }
        }
        return str1.substring(start,end);
    }

    //------------------------------------------------------- 常规1
    public static int solution(int num ){
        int bottom = num;
        int rest =0 ;
        int ans =0;
        while (bottom >= 2){
            rest =  bottom%3;
            bottom = bottom/3;
            ans =  bottom+ans;
            bottom = rest + bottom;
            if (bottom == 2){
                return ans+1;
            }
        }
        return ans;
    }
    //------------------------------------------------------- 扯淡
    public static int solution1(int num ){
        return num /2 ;
    }
}
